<?php
/**
 * Created by PhpStorm.
 * User: huanglinjie
 * Date: 2019/1/17
 * Time: 11:25 AM
 */
namespace app\common\exception;

use think\exception\Handle;

class ApiHandleException extends Handle {

    public $httpCode = 500;

    public function render(\Exception $e) {
        if(config('app_debug') == true) {
            return parent::render($e);
        }
        if ($e instanceof ApiException) {
            $this->httpCode = $e->httpCode;
        }
        $data = [
            'code' => $e->getCode(),
            'msg' => $e->getMessage(),
            'data' => []
        ];

        return json($data, $this->httpCode);
    }
}